package com.cake.liulanxiangzhu.controller;

import com.cake.liulanxiangzhu.pojo.entity.UserShop;
import com.cake.liulanxiangzhu.pojo.dto.UserShopDTO;
import com.cake.liulanxiangzhu.pojo.dto.UserShopUpdateDTO;
import com.cake.liulanxiangzhu.pojo.vo.UserShopVO;
import com.cake.liulanxiangzhu.service.UserShopService;
import com.cake.liulanxiangzhu.web.JsonPage;
import com.cake.liulanxiangzhu.web.JsonResult;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 用户信息表(UserShop)表控制层
 *
 * @author dinghao
 * @since 2023-02-21 21:02:27
 */
@RestController
@RequestMapping("/userShop")
@Validated
public class UserShopController {
    /**
     * 服务对象
     */
    @Autowired
    private UserShopService userShopService;

    /**
     * 分页查询
     *
     * @param userShop 筛选条件
     * @return 查询结果
     */
    @GetMapping("/queryUserShopListPaging")
    public JsonResult<JsonPage<UserShopVO>> queryByPage(UserShop userShop, Integer page, Integer pageSize) {
        return JsonResult.ok(this.userShopService.queryByPage(userShop, page, pageSize));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param request 主键
     * @return 单条数据
     */
    @GetMapping("/queryUserShopById")
    public JsonResult<UserShopVO> queryById(HttpServletRequest request) {
        return JsonResult.ok(this.userShopService.queryById(request));
    }

    /**
     * 新增数据
     *
     * @param userShopDto 实体
     * @return 新增结果
     */
    @PostMapping("/insertUserShop")
    public JsonResult<Void> add(HttpServletRequest request, @Valid UserShopDTO userShopDto) {
        System.out.println("request = " + request + ", userShopDto = " + userShopDto);
        this.userShopService.insert(request, userShopDto);
        return JsonResult.ok();
    }

    /**
     * 编辑数据
     *
     * @param userShopUpdateDto 实体
     * @return 编辑结果
     */
    @PostMapping("/updateUserShop")
    public JsonResult<Void> edit(HttpServletRequest request, @RequestBody UserShopUpdateDTO userShopUpdateDto) {
        System.out.println("request = " + request + ", userShopUpdateDto = " + userShopUpdateDto);
        this.userShopService.update(request, userShopUpdateDto);
        return JsonResult.ok();
    }

    /**
     * 会员充值
     *
     * @param request
     * @param userShopUpdateDTO 实体
     * @return 编辑结果
     */
    @PostMapping("/rechargeUserShop")
    public JsonResult<Void> rechargeUserShop(HttpServletRequest request, @RequestBody UserShopUpdateDTO userShopUpdateDTO) {
        System.out.println("userShopUpdateDTO = " + userShopUpdateDTO);
        this.userShopService.recharge(request, userShopUpdateDTO);
        return JsonResult.ok();
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/deleteUserShop")
    public JsonResult<Void> deleteById(Integer id) {
       this.userShopService.deleteById(id);
       return JsonResult.ok();
    }

}

